#include "stdafx.h"
#include "GuiMain.h"
#include "common.h"

GuiMain::GuiMain()
{
}


GuiMain::~GuiMain()
{
	if (m_root)
	{
		m_root->destroy();
		m_root = nullptr;
	}
}

void GuiMain::InitWindow(char *layoutFile)
{
	m_root = CEGUI::WindowManager::getSingleton().loadLayoutFromFile(layoutFile);
	CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(m_root);
	m_text_top = m_root->getChild("StaticText_top");
	m_text_position = m_root->getChild("Image/text_position");
	m_text_life = m_root->getChild("Image/text_life");
	m_text_mana = m_root->getChild("Image/text_mana");
	m_text_top->hide();
	m_text_life->setText("");
	m_text_mana->setText("");
	//m_wnd_newCharacter1 = m_root->getChild("wnd_newCharacter1");
	//CEGUI::Window *m_wnd_newCharacter2 = m_root->getChild("wnd_newCharacter2");
	//CEGUI::Window *m_wnd_delete = m_root->getChild("wnd_delete");
	//CEGUI::Window *m_wnd_delete_btn = m_wnd_delete->getChild("btn_delete");
	//CEGUI::Window *m_wnd_ok = m_root->getChild("wnd_ok");
	//CEGUI::Window *m_wnd_ok_btn = m_wnd_ok->getChild("btn_ok");
	//m_wnd_newCharacter2->hide();

	//m_wnd_ok_btn->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&GuiCharacterMgr::OnClicked_wnd_ok_btn, this));
}

void GuiMain::ShowTopText(char * text)
{
	std::string u8;
	std::string in(text);
	Ansi2Utf8(in, u8);
	m_text_top->setText((CEGUI::utf8*)u8.c_str());
	m_text_top->show();
}

void GuiMain::HideTopText()
{
	m_text_top->hide();
}

void GuiMain::SetText_position(POINT & cell)
{
	std::string buf;
	buf.resize(80);
	sprintf(&buf[0], "%d, %d", cell.x, cell.y);
	std::string txt;
	Ansi2Utf8(buf, txt);
	m_text_position->setText((CEGUI::utf8*)txt.c_str());
}

void GuiMain::SetCurrLife(int value)
{
	std::string buf;
	buf.resize(80);
	sprintf(&buf[0], "%d", value);
	std::string txt;
	Ansi2Utf8(buf, txt);
	m_text_life->setText((CEGUI::utf8*)txt.c_str());
}

void GuiMain::SetCurrMana(int value)
{
	std::string buf;
	buf.resize(80);
	sprintf(&buf[0], "%d", value);
	std::string txt;
	Ansi2Utf8(buf, txt);
	m_text_mana->setText((CEGUI::utf8*)txt.c_str());
}

//void GuiMain::OnClicked_wnd_ok_btn()
//{
//	if (!m_cb_ok_btn.empty())
//	{
//		m_cb_ok_btn();
//	}
//	else OutputDebugStringA("ok start game");
//
//}